<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY owl   "http://www.w3.org/2002/07/owl#" >
<!ENTITY xsd   "http://www.w3.org/2001/XMLSchema#" >
<!ENTITY vivo  "http://vivoweb.org/ontology/core#" >
<!ENTITY foaf  "http://xmlns.com/foaf/0.1/" >
<!ENTITY anzsrc "http://purl.org/asc/1297.0/" >
<!ENTITY for   "http://purl.org/asc/1297.0/2008/for/" >
<!ENTITY rfcd  "http://purl.org/asc/1297.0/1998/rfcd/" >
<!ENTITY seo08 "http://purl.org/asc/1297.0/2008/seo/" >
<!ENTITY seo98 "http://purl.org/asc/1297.0/1998/seo/" >
<!ENTITY ands  "http://www.ands.org.au/ontologies/ns/0.1/VITRO-ANDS.owl#" >
<!ENTITY rifcs "http://ands.org.au/standards/rif-cs/registryObjects" >
<!ENTITY event "http://purl.org/NET/c4dm/event.owl#" >
<!ENTITY dcterms "http://purl.org/dc/terms/" >
]>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
                xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
                xmlns:dc="http://purl.org/dc/elements/1.1/"
                xmlns:owl="http://www.w3.org/2002/07/owl#"
                xmlns:vitro="http://vitro.mannlib.cornell.edu/ns/vitro/0.7#"
                xmlns:ands="http://purl.org/ands/ontologies/vivo/"
                xmlns:anzsrc="http://purl.org/asc/1297.0/"
                xmlns:bibo="http://purl.org/ontology/bibo/"
                xmlns:foaf="http://xmlns.com/foaf/0.1/"
                xmlns:dcterms="http://purl.org/dc/terms/"
                xmlns:vivo="http://vivoweb.org/ontology/core#"
                xmlns:skos="http://www.w3.org/2004/02/skos/core#"
                xmlns:event="http://purl.org/NET/c4dm/event.owl#"
                xmlns:database="http://www.oclc.org/pears/"
                xmlns:oai="http://www.openarchives.org/OAI/2.0/"
                xmlns:gu="http://griffith.edu.au/ontologies/rad#"
                version="1.0">

  <xsl:output method="xml" encoding="utf-8" indent="yes" />

  <!-- various parameters to configure this stylesheet -->

  <xsl:template name="groupDescription">
    <!-- call this template on current object.
         tries to find ands:groupDescription on current object
         else it takes the value from Harvester object -->
    <xsl:choose>
      <xsl:when test="ands:groupDescription">
        <xsl:value-of select="ands:groupDescription"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="//rdf:Description[rdf:type/@rdf:resource='&ands;OAIVITROHarvest']/ands:groupDescription"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="originatingSource">
    <!-- call this template on current object.
         tries to find ands:originatingSource on current object
         else it takes the value from Harvester object -->
    <xsl:choose>
      <xsl:when test="ands:originatingSource">
        <xsl:value-of select="ands:originatingSource"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="//rdf:Description[rdf:type/@rdf:resource='&ands;OAIVITROHarvest']/ands:originatingSource"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="rdf:RDF">
    <oai:collection>
      <!-- ResearchActivity -->
      <xsl:for-each select="rdf:Description[rdf:type/@rdf:resource='&vivo;Course']">
        <xsl:call-template name="researchActivity" />
      </xsl:for-each>
      <xsl:for-each select="rdf:Description[rdf:type/@rdf:resource='&event;Event']">
        <xsl:call-template name="researchActivity" />
      </xsl:for-each>
      <xsl:for-each select="rdf:Description[rdf:type/@rdf:resource='&vivo;Program']">
        <xsl:call-template name="researchActivity" />
      </xsl:for-each>
      <xsl:for-each select="rdf:Description[rdf:type/@rdf:resource='&vivo;Project']">
        <xsl:call-template name="researchActivity" />
      </xsl:for-each>
      <xsl:for-each select="rdf:Description[rdf:type/@rdf:resource='&vivo;awardOrDistinction']">
        <xsl:call-template name="researchActivity" />
      </xsl:for-each>

      <!-- the following code can be simplified if the rdf output contains both, the spcific class-type and the
           super class type -->
      <xsl:if test="true()">
        <xsl:for-each select="rdf:Description[rdf:type/@rdf:resource='&ands;researchCatalog']">
          <xsl:call-template name="researchData" />
        </xsl:for-each>
        <xsl:for-each select="rdf:Description[rdf:type/@rdf:resource='&ands;researchCollection']">
          <xsl:call-template name="researchData" />
        </xsl:for-each>
        <xsl:for-each select="rdf:Description[rdf:type/@rdf:resource='&ands;researchDataSet']">
          <xsl:call-template name="researchData" />
        </xsl:for-each>
        <xsl:for-each select="rdf:Description[rdf:type/@rdf:resource='&ands;researchRegistry']">
          <xsl:call-template name="researchData" />
        </xsl:for-each>
        <xsl:for-each select="rdf:Description[rdf:type/@rdf:resource='&ands;researchRepository']">
          <xsl:call-template name="researchData" />
        </xsl:for-each>
      </xsl:if>
      <!-- this would be the replacement -->
      <xsl:if test="false()">
        <xsl:apply-templates
            select="rdf:Description[rdf:type/@rdf:resource='&ands;ResearchData']" />
      </xsl:if>
      <!-- People -->
      <xsl:apply-templates
          select="rdf:Description[rdf:type/@rdf:resource='&foaf;Person']" />
      <!-- Groups -->
      <xsl:apply-templates
          select="rdf:Description[rdf:type/@rdf:resource='&foaf;Organization']" />
      <!-- Services -->
      <xsl:apply-templates
          select="rdf:Description[rdf:type/@rdf:resource='&vivo;Service']"/>
    </oai:collection>
  </xsl:template>

  <!-- Activities -->
  <xsl:template name="researchActivity">
    <xsl:variable name="activitytype">
      <xsl:choose>
        <xsl:when test="rdf:type[@rdf:resource='&vivo;Course']">
          <xsl:value-of select="'course'"/>
        </xsl:when>
        <xsl:when test="rdf:type[@rdf:resource='&event;Event']">
          <xsl:value-of select="'event'"/>
        </xsl:when>
        <xsl:when test="rdf:type[@rdf:resource='&vivo;Program']">
          <xsl:value-of select="'program'"/>
        </xsl:when>
        <xsl:when test="rdf:type[@rdf:resource='&vivo;Project']">
          <xsl:value-of select="'project'"/>
        </xsl:when>
        <xsl:when test="rdf:type[@rdf:resource='&vivo;awardOrDistinction']">
          <xsl:value-of select="'award'"/>
        </xsl:when>
        <xsl:otherwise>
          <!-- TODO: check if this is the correct fallback -->
          <xsl:value-of select="'project'"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <oai:record>
      <xsl:call-template name="oaiheader">
        <xsl:with-param name="setspec" select="'Projects'"/>
      </xsl:call-template>
      <oai:metadata>
        <!-- here we genereate rif metadata -->
        <registryObjects xmlns="&rifcs;"
                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                         xsi:schemaLocation="&rifcs; http://services.ands.org.au/documentation/rifcs/schema/registryObjects.xsd">
          <xsl:variable name="groupdescription">
            <xsl:call-template name="groupDescription"/>
          </xsl:variable>
          <xsl:variable name="originatingsource">
            <xsl:call-template name="originatingSource"/>
          </xsl:variable>
          <xsl:variable name="oaiid">
            <xsl:call-template name="oaiidentifier">
              <xsl:with-param name="uri" select="@rdf:about"/>
            </xsl:call-template>
          </xsl:variable>
          <registryObject group="{$groupdescription}">
            <xsl:call-template name="key">
              <xsl:with-param name="individualuri" select="@rdf:about"/>
            </xsl:call-template>
            <originatingSource><xsl:value-of select="$originatingsource"/></originatingSource> <!-- TODO: allow alternative default value if value is not in rdf -->
            <activity type="{$activitytype}">
              <!-- identifier -->
              <xsl:call-template name="identifiers"/>
              <name type="primary">
                <namePart><xsl:value-of select="dcterms:title"/></namePart>
              </name>

              <xsl:call-template name="locationActivity" />
              <xsl:call-template name="relations" />
              <xsl:apply-templates select="vivo:hasSubjectArea" />
              <xsl:call-template name="descriptions" />
              <xsl:call-template name="relatedinfo" />

            </activity>
          </registryObject>
        </registryObjects>
      </oai:metadata>
    </oai:record>
  </xsl:template>


  <!--  Collection: an aggregation of physical or digital objects;-->
  <xsl:template name="researchData"
      match="rdf:Description[rdf:type/@rdf:resource='&ands;ResearchData']">
    <xsl:variable name="collectiontype">
      <xsl:choose>
        <xsl:when test="rdf:type[@rdf:resource='&ands;researchCatalog']">
          <xsl:value-of select="'catalogueOrIndex'"/>
        </xsl:when>
        <xsl:when test="rdf:type[@rdf:resource='&ands;researchCollection']">
          <xsl:value-of select="'collection'"/>
        </xsl:when>
        <xsl:when test="rdf:type[@rdf:resource='&ands;researchDataSet']">
          <xsl:value-of select="'dataset'"/>
        </xsl:when>
        <xsl:when test="rdf:type[@rdf:resource='&ands;researchRegistry']">
          <xsl:value-of select="'registry'"/>
        </xsl:when>
        <xsl:when test="rdf:type[@rdf:resource='&ands;researchRepository']">
          <xsl:value-of select="'repository'"/>
        </xsl:when>
        <xsl:otherwise>
          <!-- TODO: check if this is the correct fallback -->
          <xsl:value-of select="'dataset'"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <oai:record>
      <xsl:call-template name="oaiheader">
        <xsl:with-param name="setspec" select="'Collections'"/>
      </xsl:call-template>
      <oai:metadata>
        <!-- here we genereate rif metadata -->
        <registryObjects xmlns="&rifcs;"
                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                         xsi:schemaLocation="&rifcs; http://services.ands.org.au/documentation/rifcs/schema/registryObjects.xsd">
          <xsl:variable name="groupdescription">
            <xsl:call-template name="groupDescription"/>
          </xsl:variable>
          <xsl:variable name="originatingsource">
            <xsl:call-template name="originatingSource"/>
          </xsl:variable>
          <xsl:variable name="oaiid">
            <xsl:call-template name="oaiidentifier">
              <xsl:with-param name="uri" select="@rdf:about"/>
            </xsl:call-template>
          </xsl:variable>
          <registryObject group="{$groupdescription}">
            <xsl:call-template name="key">
              <xsl:with-param name="individualuri" select="@rdf:about"/>
            </xsl:call-template>
            <originatingSource><xsl:value-of select="$originatingsource"/></originatingSource> <!-- TODO: allow alternative default value if value is not in rdf -->
            <collection type="{$collectiontype}"> <!-- dateModified="{ands:firstHarvested}"> --> <!-- TODO: fixup dateModified here -->
              <xsl:call-template name="identifiers"/>

              <name type="primary">
                <namePart><xsl:value-of select="dcterms:title"/></namePart>
              </name>

              <xsl:call-template name="locationCollection" />
              <xsl:call-template name="coverage" />
              <xsl:call-template name="relations" />

              <xsl:apply-templates select="vivo:hasSubjectArea" />
              <xsl:call-template name="descriptions" />
              <xsl:call-template name="landingpageinfo" />
              <xsl:call-template name="relatedinfo" />
              <xsl:call-template name="citationinfo" />
            </collection>
          </registryObject>
        </registryObjects>
      </oai:metadata>
    </oai:record>
  </xsl:template>

  <!--  Party: a person or group; -->
  <xsl:template match="rdf:Description[rdf:type/@rdf:resource='&foaf;Person']">
    <xsl:call-template name="researchParty"/>
  </xsl:template>

  <xsl:template match="rdf:Description[rdf:type/@rdf:resource='&foaf;Organization']">
    <xsl:if test="not(rdf:type[@rdf:resource='&vivo;FundingOrganization'])">
      <!-- if this is a funding organization ignore it -->
      <xsl:call-template name="researchParty"/>
    </xsl:if>
  </xsl:template>

  <xsl:template name="researchParty">
    <xsl:variable name="partytype">
      <xsl:choose>
        <xsl:when test="rdf:type[@rdf:resource='&foaf;Person']">
          <xsl:value-of select="'person'"/>
        </xsl:when>
        <xsl:when test="rdf:type[@rdf:resource='&foaf;Organization']">
          <xsl:value-of select="'group'"/>
        </xsl:when>
        <xsl:otherwise>
          <!-- TODO: check if this is the correct fallback -->
          <xsl:value-of select="'group'"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <oai:record>
      <xsl:call-template name="oaiheader">
        <!-- TODO: do subspecs People, Groups -->
        <xsl:with-param name="setspec" select="'Parties'"/>
      </xsl:call-template>
      <oai:metadata>
        <!-- here we genereate rif metadata -->
        <registryObjects xmlns="&rifcs;"
                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                         xsi:schemaLocation="&rifcs; http://services.ands.org.au/documentation/rifcs/schema/registryObjects.xsd">
          <xsl:variable name="groupdescription">
            <xsl:call-template name="groupDescription"/>
          </xsl:variable>
          <xsl:variable name="originatingsource">
            <xsl:call-template name="originatingSource"/>
          </xsl:variable>
          <xsl:variable name="oaiid">
            <xsl:call-template name="oaiidentifier">
              <xsl:with-param name="uri" select="@rdf:about"/>
            </xsl:call-template>
          </xsl:variable>
          <registryObject group="{$groupdescription}">
            <xsl:call-template name="key">
              <xsl:with-param name="individualuri" select="@rdf:about"/>
            </xsl:call-template>
            <originatingSource><xsl:value-of select="$originatingsource"/></originatingSource> <!-- TODO: allow alternatize default value if value is not in rdf -->

            <party type="{$partytype}">
              <!-- identifier -->
              <xsl:call-template name="identifiers"/>

              <name type="primary">
                <xsl:choose>
                  <xsl:when test="$partytype='group'">
                    <xsl:call-template name="groupname" />
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:call-template name="personname" />
                  </xsl:otherwise>
                </xsl:choose>
              </name>

              <xsl:choose>
                <xsl:when test="$partytype='group'">
                  <xsl:call-template name="locationGroup" />
                </xsl:when>
                <xsl:otherwise>
                  <xsl:call-template name="locationPerson" />
                </xsl:otherwise>
              </xsl:choose>

              <xsl:call-template name="relations" />
              <xsl:apply-templates select="vivo:hasSubjectArea" />
              <xsl:call-template name="descriptions" />
              <xsl:call-template name="relatedinfo" />

            </party>
          </registryObject>
        </registryObjects>
      </oai:metadata>
    </oai:record>
  </xsl:template>


  <xsl:template match="rdf:Description[rdf:type/@rdf:resource='&vivo;Service']">
    <oai:record>
      <xsl:call-template name="oaiheader">
        <xsl:with-param name="setspec" select="'Services'"/>
      </xsl:call-template>
      <oai:metadata>
        <!-- here we genereate rif metadata -->
        <registryObjects xmlns="&rifcs;"
                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                         xsi:schemaLocation="&rifcs; http://services.ands.org.au/documentation/rifcs/schema/registryObjects.xsd">
          <xsl:variable name="groupdescription">
            <xsl:call-template name="groupDescription"/>
          </xsl:variable>
          <xsl:variable name="originatingsource">
            <xsl:call-template name="originatingSource"/>
          </xsl:variable>
          <xsl:variable name="servicetype">
            <xsl:call-template name="servicetype"/>
          </xsl:variable>
          <xsl:variable name="oaiid">
            <xsl:call-template name="oaiidentifier">
              <xsl:with-param name="uri" select="@rdf:about"/>
            </xsl:call-template>
          </xsl:variable>
          <registryObject group="{$groupdescription}">
            <xsl:call-template name="key">
              <xsl:with-param name="individualuri" select="@rdf:about"/>
            </xsl:call-template>
            <originatingSource><xsl:value-of select="$originatingsource"/></originatingSource> <!-- TODO: allow alternatize default value if value is not in rdf -->

            <!-- <service type="{vivo:type}"> -->
            <service type="{$servicetype}">
              <!-- identifier -->
              <xsl:call-template name="identifiers"/>

              <name type="primary">
                <namePart><xsl:value-of select="foaf:name"/></namePart>
              </name>

              <xsl:call-template name="locationService" />
              <xsl:call-template name="coverage" />
              <xsl:call-template name="relations" />

              <xsl:apply-templates select="vivo:hasSubjectArea" />
              <xsl:call-template name="descriptions" />
              <xsl:call-template name="landingpageinfo" />
              <xsl:call-template name="relatedinfo" />

              <!-- TODO: element accessPolicy -->

            </service>

          </registryObject>
        </registryObjects>
      </oai:metadata>
    </oai:record>
  </xsl:template>

  <!-- ======================================
       party name
       ====================================== -->
  <xsl:template name="personname">
    <!-- TODO: either export foaf:name or each part separately but not both or
         make sure, foaf:name is really a preformatted display name -->
    <!-- <xsl:apply-templates select="foaf:name"/> -->
    <xsl:apply-templates select="foaf:title"/>
    <xsl:apply-templates select="foaf:givenName"/>
    <xsl:apply-templates select="foaf:familyName"/>
    <xsl:apply-templates select="bibo:suffixName"/>
  </xsl:template>

  <xsl:template name="groupname">
    <xsl:apply-templates select="foaf:name"/>
  </xsl:template>


  <xsl:template match="foaf:name[child::node()]">
    <namePart xmlns="&rifcs;"><xsl:value-of select="."/></namePart>
  </xsl:template>

  <xsl:template match="foaf:title[child::node()]">
    <!-- Note: these three titles specifically have been requested to be
         exported in their long form. All other titles should be in their short
         form. -->
    <xsl:variable name="title">
      <xsl:choose>
        <xsl:when test=". = 'Prof'">
          <xsl:value-of select="'Professor'"/>
        </xsl:when>
        <xsl:when test=". = 'APro'">
          <xsl:value-of select="'Associate Professor'"/>
        </xsl:when>
        <xsl:when test=". = 'EmPr'">
          <xsl:value-of select="'Emeritus Professor'"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="."/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <namePart xmlns="&rifcs;" type="title"><xsl:value-of select="$title"/></namePart>
  </xsl:template>

  <xsl:template match="foaf:givenName[child::node()]">
    <namePart xmlns="&rifcs;" type="given"><xsl:value-of select="."/></namePart>
  </xsl:template>

  <xsl:template match="foaf:familyName[child::node()]">
    <namePart xmlns="&rifcs;" type="family"><xsl:value-of select="."/></namePart>
  </xsl:template>

  <xsl:template match="bibo:suffixName[child::node()]">
    <namePart xmlns="&rifcs;" type="suffix"><xsl:value-of select="."/></namePart>
  </xsl:template>

  <!-- ======================================
       identifier tags
       ====================================== -->
  <xsl:template name="identifiers">
    <xsl:apply-templates select="ands:abn"/>
    <xsl:apply-templates select="ands:arc"/>
    <xsl:apply-templates select="ands:ark"/>
    <xsl:apply-templates select="bibo:doi"/>
    <xsl:apply-templates select="bibo:handle"/>
    <xsl:apply-templates select="ands:ands"/>
    <xsl:apply-templates select="ands:infouri"/>
    <xsl:apply-templates select="ands:isil"/>
    <!-- TODO: local -->
    <xsl:apply-templates select="ands:nla"/>
    <xsl:apply-templates select="ands:purl"/>
    <xsl:apply-templates select="bibo:uri"/>
    <xsl:apply-templates select="ands:nhmrc"/>
  </xsl:template>

  <xsl:template match="ands:abn[child::node()]">
    <identifier xmlns="&rifcs;" type="abn"><xsl:value-of select="."/></identifier>
  </xsl:template>
  <xsl:template match="ands:arc[child::node()]">
    <!-- <identifier xmlns="&rifcs;" type="arc"><xsl:value-of select="."/></identifier> -->
    <identifier xmlns="&rifcs;" type="purl">http://purl.org/au-research/grants/arc/<xsl:value-of select="."/></identifier>
  </xsl:template>
  <xsl:template match="ands:ark[child::node()]">
    <identifier xmlns="&rifcs;" type="ark"><xsl:value-of select="."/></identifier>
  </xsl:template>
  <xsl:template match="bibo:doi[child::node()]">
    <!-- <identifier xmlns="&rifcs;" type="doi">doi:<xsl:value-of select="."/></identifier> -->
    <identifier xmlns="&rifcs;" type="uri">http://dx.doi.org/<xsl:value-of select="."/></identifier>
  </xsl:template>
  <xsl:template match="bibo:handle[child::node()]">
    <!-- <identifier xmlns="&rifcs;" type="handle">hdl:<xsl:value-of select="."/></identifier> -->
    <identifier xmlns="&rifcs;" type="uri">http://hdl.handle.net/<xsl:value-of select="."/></identifier>
  </xsl:template>
  <xsl:template match="ands:ands[child::node()]">
    <!-- <identifier xmlns="&rifcs;" type="handle">hdl:<xsl:value-of select="."/></identifier> -->
    <identifier xmlns="&rifcs;" type="uri">http://hdl.handle.net/<xsl:value-of select="."/></identifier>
  </xsl:template>
  <xsl:template match="ands:infouri[child::node()]">
    <identifier xmlns="&rifcs;" type="infouri"><xsl:value-of select="."/></identifier>
  </xsl:template>
  <xsl:template match="ands:isil[child::node()]">
    <identifier xmlns="&rifcs;" type="isil"><xsl:value-of select="."/></identifier>
  </xsl:template>
  <xsl:template match="ands:purl[child::node()]">
    <identifier xmlns="&rifcs;" type="purl"><xsl:value-of select="."/></identifier>
  </xsl:template>
  <xsl:template match="bibo:uri[child::node()]">
    <identifier xmlns="&rifcs;" type="uri"><xsl:value-of select="."/></identifier>
  </xsl:template>
  <xsl:template match="ands:nhmrc[child::node()]">
    <!-- <identifier xmlns="&rifcs;" type="nhmrc"><xsl:value-of select="."/></identifier> -->
    <identifier xmlns="&rifcs;" type="purl">http://purl.org/au-research/grants/nhmrc/<xsl:value-of select="."/></identifier>
  </xsl:template>
  <xsl:template match="ands:nla[child::node()]">
    <identifier xmlns="&rifcs;" type="AU-ANL:PEAU"><xsl:value-of select="."/></identifier>
  </xsl:template>

  <!-- ======================================
       coverage tags
       ====================================== -->
  <xsl:template name="coverage">
    <!-- generate coverage information -->
    <xsl:apply-templates select="dcterms:spatial"/>
    <xsl:apply-templates select="dcterms:temporal" />
  </xsl:template>

  <xsl:template match="dcterms:spatial">
    <!-- check if we have geographical coverage information -->
    <xsl:if test="normalize-space(.) != ''">
      <xsl:choose>
        <xsl:when test="@rdf:datatype='&dcterms;Box'">
          <coverage xmlns="&rifcs;">
            <spatial type="iso19139dcmiBox"><xsl:value-of select="."/></spatial>
          </coverage>
        </xsl:when>
        <xsl:when test="@rdf:datatype='&xsd;string'">
          <coverage xmlns="&rifcs;">
            <spatial type="text"><xsl:value-of select="."/></spatial>
          </coverage>
        </xsl:when>
        <!-- TODO: other spatiol encodings? -->
        <xsl:otherwise>
          <!-- TODO: what could the default be? -->
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
  </xsl:template>

  <xsl:template match="dcterms:temporal">
    <!-- check if we have geographical coverage information -->
    <xsl:if test="normalize-space(.) != ''">
      <xsl:choose>
        <xsl:when test="@rdf:datatype='&dcterms;Period'">
          <xsl:variable name="dcstart" select="."/>
          <xsl:variable name="dcend" select="."/>
          <coverage xmlns="&rifcs;">
            <temporal>
              <xsl:if test="$dcstart != ''">
                <date type="dateFrom" dateFormat="W3CDTF"><xsl:value-of select="$dcstart"/></date>
              </xsl:if>
              <xsl:if test="$dcend != ''">
                <date type="dateTo" dateFormat="W3CDTF"><xsl:value-of select="$dcend"/></date>
              </xsl:if>
            </temporal>
          </coverage>
        </xsl:when>
        <xsl:when test="@rdf:datatype='&xsd;string'">
          <coverage xmlns="&rifcs;">
            <temporal>
              <text><xsl:value-of select="."/></text>
            </temporal>
          </coverage>
        </xsl:when>
        <!-- TODO: other spatiol encodings? -->
        <xsl:otherwise>
          <!-- TODO: what could the default be? -->
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
  </xsl:template>

  <!-- ======================================
       location tags
       ====================================== -->
  <xsl:template name="locationActivity">
    <!-- generate electronic address always -->
    <location xmlns="&rifcs;">
      <address>
        <!-- <xsl:apply-templates select="vivo:workEmail"/> -->
        <!-- <xsl:apply-templates select="vivo:workPhone"/> -->
        <!-- <xsl:apply-templates select="vivo:workFax"/> -->
        <!-- <xsl:apply-templates select="ands:wsdl"/> -->
        <!-- <xsl:apply-templates select="ands:streetAddress"/> -->
        <!-- <xsl:apply-templates select="vivo:mailingAddress"/> -->
        <xsl:call-template name="landingpage" />
        <xsl:apply-templates select="vivo:webpage"/>
      </address>
    </location>
  </xsl:template>

  <xsl:template name="locationCollection">
    <!-- ANDS requires us to have only one electronic URL for collections.
         So we have to be filter out whether we crate an address at all.
         For all other object types this filter is not necessary, because we
         generate a landing page anyway. (TODO: revisit this. e.g. some institution may
         want to use it's own homepage as landing page and not hubs page) -->
    <!-- use web page as electronic address. (if there is any).
         if there is no web page then there is no electronic address.
         hub page is referred under related info, as it is not exactly the
         electronic address. (For persons this is different, because hub page
         is their profile page). For projects, it is unlikely to have an electronic address
         therefore it's the hub page.
    -->
    <xsl:variable name="streetAddressUri">
      <xsl:value-of select="ands:streetAddress"/>
    </xsl:variable>
    <xsl:variable name="mailingAddressUri">
      <xsl:value-of select="vivo:mailingAddress"/>
    </xsl:variable>
    <xsl:variable name="webpageuri">
      <xsl:value-of select="vivo:webpage"/>
    </xsl:variable>
    <xsl:variable name="webpagetype">
      <xsl:value-of select="//rdf:Description[@rdf:about=$webpageuri]/vivo:linkType"/>
    </xsl:variable>
    <!-- Don't export vivo:workEmail -->
    <xsl:if test="//rdf:Description[@rdf:about=$streetAddressUri] or
                  //rdf:Description[@rdf:about=$mailingAddressUri] or
                  vivo:workPhone[child::node() and normalize-space(.) != ''] or
                  vivo:workFax[child::node() and normalize-space(.) != ''] or
                  $webpagetype = 'People Australia URL' or
                  $webpagetype = 'Griffith Phonebook URL' or
                  $webpagetype = 'Profile Website' or
                  $webpagetype = '' or
                  $webpagetype = 'uri'">
      <location xmlns="&rifcs;">
        <address>
          <!-- <xsl:apply-templates select="vivo:workEmail"/> -->
          <xsl:apply-templates select="vivo:workPhone"/>
          <xsl:apply-templates select="vivo:workFax"/>
          <!-- <xsl:apply-templates select="ands:wsdl"/> -->
          <xsl:apply-templates select="ands:streetAddress"/>
          <xsl:apply-templates select="vivo:mailingAddress"/>
          <!-- <xsl:call-template name="landingpage" /> -->
          <xsl:apply-templates select="vivo:webpage"/>
        </address>
      </location>
    </xsl:if>
  </xsl:template>

  <xsl:template name="locationGroup">
    <!-- generate electronic address always -->
    <location xmlns="&rifcs;">
      <address>
        <xsl:apply-templates select="vivo:workEmail"/>
        <xsl:apply-templates select="vivo:workPhone"/>
        <xsl:apply-templates select="vivo:workFax"/>
        <!-- <xsl:apply-templates select="ands:wsdl"/> -->
        <xsl:apply-templates select="ands:streetAddress"/>
        <xsl:apply-templates select="vivo:mailingAddress"/>
        <xsl:call-template name="landingpage" />
        <xsl:apply-templates select="vivo:webpage"/>
      </address>
    </location>
  </xsl:template>

  <xsl:template name="locationPerson">
    <!-- generate electronic address always -->
    <location xmlns="&rifcs;">
      <address>
        <!-- <xsl:apply-templates select="vivo:workEmail"/> -->
        <xsl:apply-templates select="vivo:workPhone"/>
        <xsl:apply-templates select="vivo:workFax"/>
        <!-- <xsl:apply-templates select="ands:wsdl"/> -->
        <xsl:apply-templates select="ands:streetAddress"/>
        <xsl:apply-templates select="vivo:mailingAddress"/>
        <xsl:call-template name="landingpage" />
        <xsl:apply-templates select="vivo:webpage"/>
      </address>
    </location>
  </xsl:template>

  <xsl:template name="locationService">
    <xsl:variable name="streetAddressUri">
      <xsl:value-of select="ands:streetAddress"/>
    </xsl:variable>
    <xsl:variable name="mailingAddressUri">
      <xsl:value-of select="vivo:mailingAddress"/>
    </xsl:variable>
    <xsl:variable name="webpageuri">
      <xsl:value-of select="vivo:webpage"/>
    </xsl:variable>
    <xsl:variable name="webpagetype">
      <xsl:value-of select="//rdf:Description[@rdf:about=$webpageuri]/vivo:linkType"/>
    </xsl:variable>
    <!-- Don't export vivo:workEmail -->
    <xsl:if test="//rdf:Description[@rdf:about=$streetAddressUri] or
                  //rdf:Description[@rdf:about=$mailingAddressUri] or
                  $webpagetype = 'People Australia URL' or
                  $webpagetype = 'Griffith Phonebook URL' or
                  $webpagetype = 'Profile Website' or
                  $webpagetype = '' or
                  $webpagetype = 'uri'">
      <location xmlns="&rifcs;">
        <address>
          <!-- <xsl:apply-templates select="vivo:workEmail"/> -->
          <!-- <xsl:apply-templates select="vivo:workPhone"/> -->
          <!-- <xsl:apply-templates select="vivo:workFax"/> -->
          <!-- <xsl:apply-templates select="ands:wsdl"/> -->
          <xsl:apply-templates select="ands:streetAddress"/>
          <xsl:apply-templates select="vivo:mailingAddress"/>
          <!-- <xsl:call-template name="landingpage" /> -->
          <xsl:apply-templates select="vivo:webpage"/>
        </address>
      </location>
    </xsl:if>
  </xsl:template>

  <xsl:template name="locationFull">
    <!-- generate electronic address always -->
    <location xmlns="&rifcs;">
      <address>
        <xsl:apply-templates select="vivo:workEmail"/>
        <xsl:apply-templates select="vivo:workPhone"/>
        <xsl:apply-templates select="vivo:workFax"/>
        <!-- <xsl:apply-templates select="ands:wsdl"/> -->
        <xsl:apply-templates select="ands:streetAddress"/>
        <xsl:apply-templates select="vivo:mailingAddress"/>
        <xsl:call-template name="landingpage" />
        <xsl:apply-templates select="vivo:webpage"/>
      </address>
    </location>
  </xsl:template>

  <xsl:template match="ands:streetAddress">
    <xsl:variable name="resuri" select="@rdf:resource"/>
    <xsl:variable name="address" select="//rdf:Description[@rdf:about=$resuri]" />
    <xsl:variable name="addresslabel" select="//rdf:Description[@rdf:about=$resuri]/ands:addressLabel" />
    <xsl:if test="$address">
      <physical xmlns="&rifcs;" type="streetAddress">
        <xsl:choose>
          <xsl:when test="$addresslabel[child::node() and normalize-space(.) != '']">
            <xsl:apply-templates select="$addresslabel"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:apply-templates select="$address/vivo:addressDepartment"/>
            <xsl:apply-templates select="$address/vivo:addressStreet"/>
            <xsl:apply-templates select="$address/vivo:addressCity"/>
            <xsl:apply-templates select="$address/vivo:addressState"/>
            <xsl:apply-templates select="$address/vivo:addressCountry"/>
            <xsl:apply-templates select="$address/vivo:addressPostalCode"/>
          </xsl:otherwise>
        </xsl:choose>
      </physical>
    </xsl:if>
  </xsl:template>

  <xsl:template match="vivo:mailingAddress">
    <xsl:variable name="resuri" select="@rdf:resource"/>
    <xsl:variable name="address" select="//rdf:Description[@rdf:about=$resuri]" />
    <xsl:variable name="addresslabel" select="//rdf:Description[@rdf:about=$resuri]/ands:addressLabel" />
    <xsl:if test="$address">
      <physical xmlns="&rifcs;" type="postalAddress">
        <xsl:choose>
          <xsl:when test="$addresslabel[child::node() and normalize-space(.) != '']">
            <xsl:apply-templates select="$addresslabel"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:apply-templates select="$address/vivo:addressDepartment"/>
            <xsl:apply-templates select="$address/vivo:addressStreet"/>
            <xsl:apply-templates select="$address/vivo:addressCity"/>
            <xsl:apply-templates select="$address/vivo:addressState"/>
            <xsl:apply-templates select="$address/vivo:addressCountry"/>
            <xsl:apply-templates select="$address/vivo:addressPostalCode"/>
          </xsl:otherwise>
        </xsl:choose>
      </physical>
    </xsl:if>
  </xsl:template>

  <xsl:template match="ands:addressLabel[child::node() and normalize-space(.) != '']">
    <addressPart xmlns="&rifcs;" type="text"><xsl:value-of select="."/></addressPart>
  </xsl:template>

  <xsl:template match="vivo:addressDepartment[child::node() and normalize-space(.) != '']">
    <addressPart xmlns="&rifcs;" type="locationDescriptor"><xsl:value-of select="."/></addressPart>
  </xsl:template>

  <xsl:template match="vivo:addressStreet[child::node() and normalize-space(.) != '']">
    <addressPart xmlns="&rifcs;" type="streetName"><xsl:value-of select="."/></addressPart>
  </xsl:template>

  <xsl:template match="vivo:addressCity[child::node() and normalize-space(.) != '']">
    <addressPart xmlns="&rifcs;" type="suburbOrPlaceOrLocality"><xsl:value-of select="."/></addressPart>
  </xsl:template>

  <xsl:template match="vivo:addressState[child::node() and normalize-space(.) != '']">
    <addressPart xmlns="&rifcs;" type="stateOrTerritory"><xsl:value-of select="."/></addressPart>
  </xsl:template>

  <xsl:template match="vivo:addressCountry[child::node() and normalize-space(.) != '']">
    <addressPart xmlns="&rifcs;" type="country"><xsl:value-of select="."/></addressPart>
  </xsl:template>

  <xsl:template match="vivo:addressPostalCode[child::node() and normalize-space(.) != '']">
    <addressPart xmlns="&rifcs;" type="postCode"><xsl:value-of select="."/></addressPart>
  </xsl:template>

  <xsl:template match="vivo:workEmail[child::node() and normalize-space(.) != '']">
    <electronic xmlns="&rifcs;" type="email">
      <value><xsl:value-of select="."/></value>
    </electronic>
  </xsl:template>

  <xsl:template match="vivo:workFax[child::node() and normalize-space(.) != '']">
    <electronic xmlns="&rifcs;" type="fax">
      <value><xsl:value-of select="."/></value>
    </electronic>
  </xsl:template>

  <xsl:template match="vivo:workPhone[child::node() and normalize-space(.) != '']">
    <electronic xmlns="&rifcs;" type="voice">
      <value><xsl:value-of select="."/></value>
    </electronic>
  </xsl:template>

  <xsl:template name="landingpage">
    <xsl:variable name="linkURI" select="@rdf:about" />
    <electronic xmlns="&rifcs;" type="url">
      <value><xsl:value-of select="$linkURI"/></value>
    </electronic>
  </xsl:template>

  <xsl:template name="landingpageinfo">
    <xsl:variable name="linkURI" select="@rdf:about" />
    <relatedInfo xmlns="&rifcs;">
        <identifier type="uri"><xsl:value-of select="$linkURI"/></identifier>
        <title>Griffith Research Hub</title>
    </relatedInfo>
  </xsl:template>

  <xsl:template name="servicetype">
    <xsl:variable name="typeuri" select="dcterms:type/@rdf:resource"/>
    <xsl:choose>
      <xsl:when test="$typeuri = '&ands;HarvestOAIPMH'">
        <xsl:value-of select="'harvest-oaipmh'"/>
      </xsl:when>
      <xsl:when test="$typeuri = '&ands;HarvestOAIPMH'">
        <xsl:value-of select="'harvest-oaipmh'"/>
      </xsl:when>
      <xsl:when test="$typeuri = '&ands;SearchHTTP'">
        <xsl:value-of select="'search-http'"/>
      </xsl:when>
      <xsl:when test="$typeuri = '&ands;SearchOpenSearch'">
        <xsl:value-of select="'search-opensearch'"/>
      </xsl:when>
      <xsl:when test="$typeuri = '&ands;SearchSRU'">
        <xsl:value-of select="'search-sru'"/>
      </xsl:when>
      <xsl:when test="$typeuri = '&ands;SearchSRW'">
        <xsl:value-of select="'search-srw'"/>
      </xsl:when>
      <xsl:when test="$typeuri = '&ands;Searchz3950'">
        <xsl:value-of select="'search-z3950'"/>
      </xsl:when>
      <xsl:when test="$typeuri = '&ands;SyndicateATOM'">
        <xsl:value-of select="'syndicate-atom'"/>
      </xsl:when>
      <xsl:when test="$typeuri = '&ands;SyndicateRSS'">
        <xsl:value-of select="'syndicate-rss'"/>
      </xsl:when>
      <xsl:when test="$typeuri = '&ands;ServiceCreate'">
        <xsl:value-of select="'create'"/>
      </xsl:when>
      <xsl:when test="$typeuri = '&ands;ServiceGenerate'">
        <xsl:value-of select="'generate'"/>
      </xsl:when>
      <xsl:when test="$typeuri = '&ands;ServiceReport'">
        <xsl:value-of select="'report'"/>
      </xsl:when>
      <xsl:when test="$typeuri = '&ands;ServiceAnnotate'">
        <xsl:value-of select="'annotate'"/>
      </xsl:when>
      <xsl:when test="$typeuri = '&ands;ServiceTransform'">
        <xsl:value-of select="'transform'"/>
      </xsl:when>
      <xsl:when test="$typeuri = '&ands;ServiceAssemble'">
        <xsl:value-of select="'assemble'"/>
      </xsl:when>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="vivo:webpage">
    <xsl:variable name="resuri" select="@rdf:resource"/>
    <xsl:variable name="linkURI" select="//rdf:Description[@rdf:about=$resuri]/vivo:linkURI" />
    <xsl:variable name="linkType" select="//rdf:Description[@rdf:about=$resuri]/vivo:linkType" />
    <!-- generate url link only if we have a url to link to -->
    <!-- only output links to People Australia as electronic addresses -->
    <xsl:if test="$linkURI and
                  ($linkType = 'People Australia URL' or
                   $linkType = 'Griffith Phonebook URL' or
                   $linkType = 'Profile Website' or
                   $linkType = '' or
                   $linkType = 'uri')">
      <!-- vivo:linkType :
           'Affiliates Website',
           'Blog Website',
           'Facebook Page',
           'Griffith Phonebook URL',
           'GRO Entry',
           'People Australia URL',
           'Personal Website',
           'Profile Website',
           'Publication',
           'Related Link' -->
      <electronic xmlns="&rifcs;" type="url">
        <value><xsl:value-of select="$linkURI"/></value>
      </electronic>
    </xsl:if>
  </xsl:template>

  <xsl:template match="vivo:webpage" mode="relatedinfo">
    <xsl:variable name="resuri" select="@rdf:resource"/>
    <xsl:variable name="linkURI" select="//rdf:Description[@rdf:about=$resuri]/vivo:linkURI" />
    <xsl:variable name="linkType" select="//rdf:Description[@rdf:about=$resuri]/vivo:linkType" />
    <!-- generate related info element only if we have a url to link to -->
    <!-- only output links not to People Australia as electronic addresses -->
    <xsl:if test="$linkURI and
                  $linkType != 'People Australia URL' and
                  $linkType != 'Griffith Phonebook URL' and
                  $linkType != 'Profile Website' and
                  $linkType != '' and
                  $linkType != 'uri'">
      <relatedInfo xmlns="&rifcs;"><xsl:value-of select="$linkURI"/></relatedInfo>
    </xsl:if>
  </xsl:template>

  <xsl:template match="ands:nla[child::node()]" mode="relatedinfo">
    <!-- render nla id as electronic url address -->
    <relatedInfo xmlns="&rifcs;"><xsl:value-of select="."/></relatedInfo>
  </xsl:template>

  <!-- <xsl:template match="ands:wsdl"> -->
  <!--   <rifcs:electronic type="wsdl"><xsl:value-of select="*/rdf:Description[@rdf:about=@rdf:resource]/vivo:linkURI"/></rifcs:electronic> -->
  <!-- </xsl:template> -->


  <!-- ======================================
       relatedinfo tags
       ====================================== -->

  <xsl:template name="relatedinfo">
    <xsl:apply-templates select="vivo:webpage" mode="relatedinfo"/>
    <!-- <xsl:apply-templates select="ands:nla" mode="relatedinfo" /> -->
  </xsl:template>


  <!-- ======================================
       description tags
       ====================================== -->

  <xsl:template name="descriptions">
    <xsl:apply-templates select="vivo:description"/>
    <xsl:apply-templates select="bibo:shortDescription"/>
    <xsl:apply-templates select="foaf:logo"/>
    <xsl:apply-templates select="skos:note"/>
    <xsl:apply-templates select="dcterms:rights"/>
    <xsl:apply-templates select="dcterms:accessRights"/>
  </xsl:template>

  <xsl:template match="vivo:description[child::node()]">
    <description xmlns="&rifcs;" type="full"><xsl:value-of select="." /></description>
  </xsl:template>

  <xsl:template match="bibo:shortDescription[child::node()]">
    <description xmlns="&rifcs;" type="brief"><xsl:value-of select="." /></description>
  </xsl:template>

  <xsl:template match="foaf:logo">
    <description xmlns="&rifcs;" type="logo"><xsl:value-of select="@rdf:resource" /></description>
  </xsl:template>

  <xsl:template match="skos:note[child::node()]">
    <description xmlns="&rifcs;" type="note"><xsl:value-of select="." /></description>
  </xsl:template>

  <xsl:template match="dcterms:rights[child::node()]">
    <description xmlns="&rifcs;" type="rights"><xsl:value-of select="." /></description>
  </xsl:template>

  <xsl:template match="dcterms:accessRights[child::node()]">
    <description xmlns="&rifcs;" type="accessRights"><xsl:value-of select="." /></description>
  </xsl:template>

  <!-- ======================================
       subject tags
       ====================================== -->
  <xsl:template match="vivo:hasSubjectArea">
    <xsl:variable name="resuri" select="@rdf:resource"/>
    <xsl:choose>
      <xsl:when test="starts-with($resuri, '&seo98;')">
        <subject xmlns="&rifcs;" type="anzsrc-seo"><xsl:value-of select="substring-after($resuri, '&seo98;')"/></subject>
      </xsl:when>
      <xsl:when test="starts-with($resuri, '&seo08;')">
        <subject xmlns="&rifcs;" type="anzsrc-seo"><xsl:value-of select="substring-after($resuri, '&seo08;')"/></subject>
      </xsl:when>
      <xsl:when test="starts-with($resuri, '&rfcd;')">
        <subject xmlns="&rifcs;" type="anzsrc-rfcd"><xsl:value-of select="substring-after($resuri, '&rfcd;')"/></subject>
      </xsl:when>
      <xsl:when test="starts-with($resuri, '&for;')">
        <subject xmlns="&rifcs;" type="anzsrc-for"><xsl:value-of select="substring-after($resuri, '&for;')"/></subject>
      </xsl:when>
      <!-- TODO: anzsrc-toa -->
      <xsl:otherwise>
        <!-- TODO: check if @rdf:resource is available and use it, else use string content -->
        <!-- generate subject only if it is in rdf -->
        <xsl:if test="//rdf:Description[@rdf:about=$resuri]">
          <subject xmlns="&rifcs;" type="local"><xsl:value-of select="//rdf:Description[@rdf:about=$resuri]/rdfs:label"/></subject>
        </xsl:if>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>


  <!-- ======================================
       relation tags
       ====================================== -->

  <xsl:template name="relations">
    <xsl:apply-templates select="vivo:hasMember"/>
    <xsl:apply-templates select="vivo:memberOf"/>
    <xsl:apply-templates select="vivo:hasCurrentMember"/>
    <xsl:apply-templates select="vivo:currentMemberOf"/>
    <xsl:apply-templates select="ands:describes"/>
    <xsl:apply-templates select="ands:isDescribedBy"/>
    <xsl:apply-templates select="vivo:hasPart"/>
    <xsl:apply-templates select="vivo:isPartOf"/>
    <xsl:apply-templates select="dcterms:relation"/>
    <xsl:apply-templates select="ands:isLocatedIn"/>
    <xsl:apply-templates select="ands:isLocationFor"/>
    <xsl:apply-templates select="ands:hasCollector"/>
    <xsl:apply-templates select="ands:isCollectorOf"/>
    <xsl:apply-templates select="ands:isManagedBy"/>
    <xsl:apply-templates select="ands:isManagerOf"/>
    <xsl:apply-templates select="ands:supports"/>
    <xsl:apply-templates select="ands:isSupportedBy"/>
    <xsl:apply-templates select="ands:isOutputOf"/>
    <xsl:apply-templates select="ands:hasOutput"/>
    <xsl:apply-templates select="ands:isParticipantIn"/>
    <xsl:apply-templates select="ands:hasParticipant"/>
    <xsl:apply-templates select="ands:isOwnerOf"/>
    <xsl:apply-templates select="ands:isOwnedBy"/>
    <!-- TODO: decide what to do here.
         do not export these as rfcs:relatedObjects.
         we only need them to generate the project description -->
    <!-- <xsl:apply-templates select="vivo:fundedByAgent"/> -->
    <!-- <xsl:apply-templates select="vivo:fundingAgentFor"/> -->
    <xsl:apply-templates select="ands:hasPointOfContact" />
    <xsl:apply-templates select="ands:isPointOfContactFor" />
  </xsl:template>

  <xsl:template match="vivo:hasMember">
    <xsl:call-template name="relatedObjects">
      <xsl:with-param name="reltype" select="'hasMember'"/>
      <xsl:with-param name="desturi" select="@rdf:resource"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="vivo:memberOf">
    <xsl:call-template name="relatedObjects">
      <xsl:with-param name="reltype" select="'isMemberOf'"/>
      <xsl:with-param name="desturi" select="@rdf:resource"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="vivo:hasCurrentMember">
    <xsl:call-template name="relatedObjects">
      <xsl:with-param name="reltype" select="'hasMember'"/>
      <xsl:with-param name="desturi" select="@rdf:resource"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="vivo:currentMemberOf">
    <xsl:call-template name="relatedObjects">
      <xsl:with-param name="reltype" select="'isMemberOf'"/>
      <xsl:with-param name="desturi" select="@rdf:resource"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="ands:describes">
    <xsl:call-template name="relatedObjects">
      <xsl:with-param name="reltype" select="'describes'"/>
      <xsl:with-param name="desturi" select="@rdf:resource"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="ands:isDescribedBy">
    <xsl:call-template name="relatedObjects">
      <xsl:with-param name="reltype" select="'isDescribedBy'"/>
      <xsl:with-param name="desturi" select="@rdf:resource"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="vivo:hasPart">
    <xsl:call-template name="relatedObjects">
      <xsl:with-param name="reltype" select="'hasPart'"/>
      <xsl:with-param name="desturi" select="@rdf:resource"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="vivo:isPartOf">
    <xsl:call-template name="relatedObjects">
      <xsl:with-param name="reltype" select="'isPartOf'"/>
      <xsl:with-param name="desturi" select="@rdf:resource"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="dcterms:relation">
    <xsl:call-template name="relatedObjects">
      <xsl:with-param name="reltype" select="'hasAssociationWith'"/>
      <xsl:with-param name="desturi" select="@rdf:resource"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="ands:isLocatedIn">
    <xsl:call-template name="relatedObjects">
      <xsl:with-param name="reltype" select="'isLocatedIn'"/>
      <xsl:with-param name="desturi" select="@rdf:resource"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="ands:isLocationFor">
    <xsl:call-template name="relatedObjects">
      <xsl:with-param name="reltype" select="'isLocationFor'"/>
      <xsl:with-param name="desturi" select="@rdf:resource"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="ands:hasCollector">
    <xsl:call-template name="relatedObjects">
      <xsl:with-param name="reltype" select="'hasCollector'"/>
      <xsl:with-param name="desturi" select="@rdf:resource"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="ands:isCollectorOf">
    <xsl:call-template name="relatedObjects">
      <xsl:with-param name="reltype" select="'isCollectorOf'"/>
      <xsl:with-param name="desturi" select="@rdf:resource"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="ands:isManagedBy">
    <xsl:call-template name="relatedObjects">
      <xsl:with-param name="reltype" select="'isManagedBy'"/>
      <xsl:with-param name="desturi" select="@rdf:resource"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="ands:isManagerOf">
    <xsl:call-template name="relatedObjects">
      <xsl:with-param name="reltype" select="'isManagerOf'"/>
      <xsl:with-param name="desturi" select="@rdf:resource"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="ands:supports">
    <xsl:call-template name="relatedObjects">
      <xsl:with-param name="reltype" select="'supports'"/>
      <xsl:with-param name="desturi" select="@rdf:resource"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="ands:isSupportedBy">
    <xsl:call-template name="relatedObjects">
      <xsl:with-param name="reltype" select="'isSupportedBy'"/>
      <xsl:with-param name="desturi" select="@rdf:resource"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="ands:isOutputOf">
    <xsl:call-template name="relatedObjects">
      <xsl:with-param name="reltype" select="'isOutputOf'"/>
      <xsl:with-param name="desturi" select="@rdf:resource"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="ands:hasOutput">
    <xsl:call-template name="relatedObjects">
      <xsl:with-param name="reltype" select="'hasOutput'"/>
      <xsl:with-param name="desturi" select="@rdf:resource"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="ands:isParticipantIn">
    <xsl:call-template name="relatedObjects">
      <xsl:with-param name="reltype" select="'isParticipantIn'"/>
      <xsl:with-param name="desturi" select="@rdf:resource"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="ands:hasParticipant">
    <xsl:call-template name="relatedObjects">
      <xsl:with-param name="reltype" select="'hasParticipant'"/>
      <xsl:with-param name="desturi" select="@rdf:resource"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="ands:isOwnerOf">
    <xsl:call-template name="relatedObjects">
      <xsl:with-param name="reltype" select="'isOwnerOf'"/>
      <xsl:with-param name="desturi" select="@rdf:resource"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="ands:isOwnedBy">
    <xsl:call-template name="relatedObjects">
      <xsl:with-param name="reltype" select="'isOwnedBy'"/>
      <xsl:with-param name="desturi" select="@rdf:resource"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="vivo:fundedByAgent">
    <xsl:call-template name="relatedObjects">
      <xsl:with-param name="reltype" select="'isFundedBy'"/>
      <xsl:with-param name="desturi" select="@rdf:resource"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="vivo:fundingAgentFor">
    <xsl:call-template name="relatedObjects">
      <xsl:with-param name="reltype" select="'isFunderOf'"/>
      <xsl:with-param name="desturi" select="@rdf:resource"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="ands:hasPointOfContact">
    <xsl:call-template name="relatedObjects">
      <xsl:with-param name="reltype" select="'pointOfContact'"/>
      <xsl:with-param name="desturi" select="@rdf:resource"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="ands:isPointOfContactFor">
    <xsl:call-template name="relatedObjects">
      <xsl:with-param name="reltype" select="'isPointOfContact'"/>
      <xsl:with-param name="desturi" select="@rdf:resource"/>
    </xsl:call-template>
  </xsl:template>

  <!-- ======================================
       generic relation template
       ====================================== -->
  <xsl:template name="relatedObjects">
    <xsl:param name="reltype"/>
    <xsl:param name="desturi"/>
    <xsl:param name="reldesc"/>
    <xsl:param name="relurl"/>
    <xsl:if test="$desturi">
      <!-- check that $desturi is available -->
      <xsl:if test="//rdf:Description[@rdf:about=$desturi]">
        <!-- <xsl:variable name="oaiid"> -->
        <!--   <xsl:call-template name="oaiidentifier"> -->
        <!--     <xsl:with-param name="uri" select="$desturi"/> -->
        <!--   </xsl:call-template> -->
        <!-- </xsl:variable> -->
        <relatedObject xmlns="&rifcs;">
          <xsl:call-template name="key">
            <xsl:with-param name="individualuri" select="$desturi"/>
          </xsl:call-template>
          <relation type="{$reltype}">
            <xsl:if test="$reldesc">
              <description><xsl:value-of select="$reldesc"/></description>
            </xsl:if>
            <xsl:if test="$relurl">
              <description><xsl:value-of select="$relurl"/></description>
            </xsl:if>
          </relation>
        </relatedObject>
      </xsl:if>
    </xsl:if>
  </xsl:template>

  <xsl:template name="key">
    <!-- using oaiid would be a better option -->
    <xsl:param name="individualuri" />
    <key xmlns="&rifcs;"><xsl:value-of select="concat('griffith.edu.au/', substring-after($individualuri, 'individual/'))" /></key>
  </xsl:template>


  <!-- ======================================
       generate oai identifier from uri
       generic form: oai:domain.name:local-id
       ====================================== -->
  <xsl:template name="citationinfo">
    <!-- check all possibilites separately to ensure we generate only one citationInfo element
         TODO: check with ANDS about multiplicity of citationInfo elements. -->
    <xsl:choose>
      <xsl:when test="&ands;citHarvard">
        <xsl:apply-templates select="&ands;citHarvard"/>
      </xsl:when>
      <xsl:when test="&ands;citAPA">
        <xsl:apply-templates select="&ands;citAPA"/>
      </xsl:when>
      <xsl:when test="&ands;citMLA">
        <xsl:apply-templates select="&ands;citMLA"/>
      </xsl:when>
      <xsl:when test="&ands;citVancouver">
        <xsl:apply-templates select="&ands;citVancouver"/>
      </xsl:when>
      <xsl:when test="&ands;citIEEE">
        <xsl:apply-templates select="&ands;citIEEE"/>
      </xsl:when>
      <xsl:when test="&ands;citCSE">
        <xsl:apply-templates select="&ands;citCSE"/>
      </xsl:when>
      <xsl:when test="&ands;citChicago">
        <xsl:apply-templates select="&ands;citChicago"/>
      </xsl:when>
      <xsl:when test="&ands;citAMA">
        <xsl:apply-templates select="&ands;citAMA"/>
      </xsl:when>
      <xsl:when test="&ands;citAgpsAGIMO">
        <xsl:apply-templates select="&ands;citAgpsAGIMO"/>
      </xsl:when>
      <xsl:when test="&ands;citAGLC">
        <xsl:apply-templates select="&ands;citAGLC"/>
      </xsl:when>
      <xsl:when test="&ands;citACS">
        <xsl:apply-templates select="&ands;citACS"/>
      </xsl:when>
      <xsl:when test="&ands;citDatacite">
        <xsl:apply-templates select="&ands;citDatacite"/>
      </xsl:when>
      <xsl:otherwise>
        <!-- <xsl:call-template name="citationmetadata"/> -->
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="&ands;citHarvard">
    <xsl:call-template name="fullcitation">
      <xsl:with-param name="cittype" select="'Harvard'"/>
    </xsl:call-template>
  </xsl:template>
  <xsl:template match="&ands;citAPA">
    <xsl:call-template name="fullcitation">
      <xsl:with-param name="cittype" select="'APA'"/>
    </xsl:call-template>
  </xsl:template>
  <xsl:template match="&ands;citMLA">
    <xsl:call-template name="fullcitation">
      <xsl:with-param name="cittype" select="'MLA'"/>
    </xsl:call-template>
  </xsl:template>
  <xsl:template match="&ands;citVancouver">
    <xsl:call-template name="fullcitation">
      <xsl:with-param name="cittype" select="'Vancouver'"/>
    </xsl:call-template>
  </xsl:template>
  <xsl:template match="&ands;citIEEE">
    <xsl:call-template name="fullcitation">
      <xsl:with-param name="cittype" select="'IEEE'"/>
    </xsl:call-template>
  </xsl:template>
  <xsl:template match="&ands;citCSE">
    <xsl:call-template name="fullcitation">
      <xsl:with-param name="cittype" select="'CSE'"/>
    </xsl:call-template>
  </xsl:template>
  <xsl:template match="&ands;citChicago">
    <xsl:call-template name="fullcitation">
      <xsl:with-param name="cittype" select="'Chicago'"/>
    </xsl:call-template>
  </xsl:template>
  <xsl:template match="&ands;citAMA">
    <xsl:call-template name="fullcitation">
      <xsl:with-param name="cittype" select="'AMA'"/>
    </xsl:call-template>
  </xsl:template>
  <xsl:template match="&ands;citAgpsAGIMO">
    <xsl:call-template name="fullcitation">
      <xsl:with-param name="cittype" select="'AGPS-AGIMO'"/>
    </xsl:call-template>
  </xsl:template>
  <xsl:template match="&ands;citAGLC">
    <xsl:call-template name="fullcitation">
      <xsl:with-param name="cittype" select="'AGLC'"/>
    </xsl:call-template>
  </xsl:template>
  <xsl:template match="&ands;citACS">
    <xsl:call-template name="fullcitation">
      <xsl:with-param name="cittype" select="'ACS'"/>
    </xsl:call-template>
  </xsl:template>
  <xsl:template match="&ands;citDatacite">
    <xsl:call-template name="fullcitation">
      <xsl:with-param name="cittype" select="'Datacite'"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template name="fullcitation">
    <xsl:param name="cittype"/>
    <citationInfo xmlns="&rifcs;">
      <fullCitation style="{$cittype}"><xsl:value-of select="."/></fullCitation>
    </citationInfo>
  </xsl:template>

  <xsl:template name="citationmetadata">
    <!-- TODO: needs to be done....
               difficult to implement, because each element is required,
               but can be populated by many different source properties. -->
    <citationInfo xmlns="&rifcs;">
      <citationMetadata>
        <identifier type=""/> 1
        <contributor>
          <namePart seq=""/>
        </contributor>
        <title/> 1
        <edition/> 1
        <placePublished/> 1
        <date type=".."/> *
        <url/> 1
        <context/> 1
      </citationMetadata>
    </citationInfo>
  </xsl:template>


  <!-- ======================================
       generate oai identifier from uri
       generic form: oai:domain.name:local-id
       ====================================== -->
  <xsl:template name="oaiidentifier">
    <!-- e.g.: split about uri into domain and path and use these to generate oai id -->
    <xsl:param name="uri"/>
    <xsl:variable name="domain">
      <!-- skip http:// and use all values until first : or / -->
      <xsl:value-of select="substring-before(substring-after($uri, 'http://'), '/')"/>
    </xsl:variable>
    <xsl:variable name="pathid">
      <!-- skip http:// and use all after first / -->
      <xsl:value-of select="substring-after(substring-after($uri, 'http://'), 'individual/')"/>
    </xsl:variable>
    <xsl:value-of select="concat('oai:', $domain, ':', $pathid)"/>
  </xsl:template>

  <!-- generate oai record header -->
  <xsl:template name="oaiheader">
    <xsl:param name="setspec"/>
    <xsl:variable name="oaiid">
      <xsl:call-template name="oaiidentifier">
        <xsl:with-param name="uri" select="@rdf:about"/>
      </xsl:call-template>
    </xsl:variable>
    <database:recordid><xsl:value-of select="$oaiid"/></database:recordid> <!-- oaicat XML File storage needs this -->
    <oai:header> <!-- status="deleted"> -->
      <oai:identifier><xsl:value-of select="$oaiid"/></oai:identifier>
      <oai:datestamp><xsl:value-of select="vitro:modTime"/></oai:datestamp>
      <!-- <oai:setSpec>hierarchical:colon:separated:keyword:list</oai:setSpec> -->
      <xsl:choose>
        <xsl:when test="Parties">
          <xsl:choose>
            <xsl:when test="foaf:Organization">
              <oai:setSpec><xsl:value-of select="'Parties:Groups'"/></oai:setSpec>
            </xsl:when>
            <xsl:when test="foaf:Person">
              <oai:setSpec><xsl:value-of select="'Parties:People'"/></oai:setSpec>
            </xsl:when>
            <xsl:otherwise>
              <oai:setSpec><xsl:value-of select="$setspec"/></oai:setSpec>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:when>
        <xsl:otherwise>
          <oai:setSpec><xsl:value-of select="$setspec"/></oai:setSpec>
        </xsl:otherwise>
      </xsl:choose>
    </oai:header>
  </xsl:template>

  <!-- oai record has following fields:
      header
      metadata
      about (optional but may be interesting) -->

  <xsl:template match="text()"/>

</xsl:stylesheet>
